﻿//using System;
//using System.Collections.Generic;
//using System.Text;

//using System.Runtime.InteropServices;

//using SuperMapLib;

//namespace JR_RouteAlarm
//{
//    class CrossArea : IWorkspace
//    {        
//        /*変数*/
//        private AxSuperMapLib.AxSuperWorkspace superWksp = null;
//        private soDatasets objDSs = null;
//        private AxSuperMapLib.AxSuperMap objMap = null;
//        private string strLayerName = String.Empty;
//        private string strMapName = String.Empty;

//        public CrossArea(AxSuperMapLib.AxSuperWorkspace superWksp, AxSuperMapLib.AxSuperMap objMap, soDatasets objDSs)
//        {
//            this.superWksp = superWksp;
//            this.objDSs = objDSs;
//            this.objMap = objMap;
//        }

//        private void AddBufferLayerToMap()
//        {
//            soLayers objLayers = null;
//            soLayer objLayer200m = null;
//            soLayer objLayerSrc = null;

//            objLayers = objMap.Layers;
//            objLayer200m = objMap.Layers.AddDataset(objDSs[objDSs.Count], false);
//            if (objLayer200m != null)
//            {
//                objLayerSrc = objLayers["joukoujouR@areamap"];
//                if (!objLayers.MoveTo(objLayers.Count, objLayers.FindLayer(objLayerSrc)))
//                {
//                    throw new Exception("Layer move failed!");
//                }

//                Marshal.ReleaseComObject(objLayerSrc);
//                objLayerSrc = null;
//                Marshal.ReleaseComObject(objLayer200m);
//                objLayer200m = null;
//            }

//            Marshal.ReleaseComObject(objLayers);
//            objLayers = null;
//        }

//        private void SetTheme(soLayer objLayer)
//        {
//            SetColor(objLayer);
//            SetLabel(objLayer);

//            Marshal.ReleaseComObject(objLayer);
//            objLayer = null;
//        }

//        private void SetColor(soLayer objLayer)
//        {
//            soThemeUnique objThemeUnique = null;

//            objThemeUnique = objLayer.ThemeUnique;

//            objThemeUnique.Field = Utility.CROSS_AREA_FIELD;
//            objThemeUnique.Filter = 
//                RouteDataset.FLD_FEATURE_CD + ", " + RouteDataset.FLD_DAIBUN_CD + ", " + RouteDataset.FLD_TSUUSHO_CD;
//            objThemeUnique.Caption = Utility.THEME_COLOR_CAPTION;
//            objThemeUnique.MakeDefault();

//            //soColors objColors = null;
//            //soStyle objStyle = null;

//            //objColors = new soColors();
//            //objColors.MakeRandomColorset(objThemeUnique.ValueCount);
//            //objStyle = objThemeUnique.DefaultStyle;
//            //objStyle.BrushStyle = Utility.BRUSH_STYLE;
//            for (int i = 0; i < objThemeUnique.ValueCount; i++)
//            { 
//                objThemeUnique.set_ItemCaption(i, (i+1).ToString());
//            }

//            //Marshal.ReleaseComObject(objStyle);
//            //objStyle = null;
//            //Marshal.ReleaseComObject(objColors);
//            //objColors = null;
//            Marshal.ReleaseComObject(objThemeUnique);
//            objThemeUnique = null;
//        }

//        private void SetLabel(soLayer objLayer)
//        {
//            soThemeLabel objThemeLabel = null;
//            soTextStyle objTextStyle = null;

//            objThemeLabel = objLayer.ThemeLabel;

//            objThemeLabel.Field = RouteDataset.FLD_LABEL_TEXT;
//            objThemeLabel.Filter =
//                RouteDataset.FLD_FEATURE_CD + ", " + RouteDataset.FLD_DAIBUN_CD + ", " + RouteDataset.FLD_TSUUSHO_CD;

//            objThemeLabel.Caption = Utility.THEME_LABLE_CAPTION;
//            objThemeLabel.BackShape = seTextBackShape.sctBackRect;
//            objThemeLabel.AutoAvoidOverlapped = true;
//            //objThemeLabel.LineDirection = seLabelLineDirection.sclDirectionLeftBottomToRightTop;
//            objThemeLabel.ShowLeaderLines = true;
//            objThemeLabel.EnableFlow = true;
//            objThemeLabel.TextControlMode = seTextControlMode.scmTextControlWrapText;
//            objThemeLabel.SingleLineCharCount = Utility.MAX_LINE_CHAR_COUNT;
//            objThemeLabel.OnTop = true;

//            objTextStyle = new soTextStyle();
//            objTextStyle.FontHeight = Utility.LABEL_FONT_HIGHT;
//            objTextStyle.FontWidth = Utility.LABEL_FONT_WIDTH;
//            objThemeLabel.TextStyle = objTextStyle;

//            Marshal.ReleaseComObject(objTextStyle);
//            objTextStyle = null;
//            Marshal.ReleaseComObject(objThemeLabel);
//            objThemeLabel = null;
//        }

//        #region IWorkspace メンバ

//        public void Initialize()
//        {
//            soMaps objMaps = null;

//            objMaps = superWksp.Maps;
//            strMapName = objMaps[1];
//            objMap.Connect(superWksp.CtlHandle);
//            if (!objMap.OpenMap(strMapName))
//            {
//                throw new Exception("Open map failed!");
//            }

//            Marshal.ReleaseComObject(objMaps);
//            objMaps = null;
//        }

//        public void SaveToWksp()
//        {
//            AddBufferLayerToMap();
//            strLayerName = objDSs[objDSs.Count].Name + "@" + Utility.s_DatasourceAlias;
//            SetTheme(objMap.Layers[strLayerName]);

//            objMap.SaveMap();
//        }

//        public void OutputAsFile()
//        {
//            throw new Exception("The method or operation is not implemented.");
//        }

//        public void ReleaseMemory()
//        {
//            objMap.Close();
//            objMap.Disconnect();

//            //Marshal.ReleaseComObject(objMap); //COMではない？
//            objMap = null;
//            Marshal.ReleaseComObject(objDSs);
//            objDSs = null;
//        }

//        #endregion
//    }
//}
